// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

// import 'dart:async';

// import 'dart:io';
// import 'package:flutter/material.dart';
// import 'package:flutter/services.dart';
// import 'package:device_info/device_info.dart';
// import 'package:get/get.dart';

// class GetDeviceInfo extends StatefulWidget {
//   @override
//   _GetDeviceInfoState createState() => _GetDeviceInfoState();
// }

// class _GetDeviceInfoState extends State<GetDeviceInfo> {
//   @override
//   Widget build(BuildContext context) {
//     return MaterialApp(
//       home: Scaffold(
//         appBar: AppBar(
//           title: Text(
//               Platform.isAndroid ? 'Android Device Info' : 'iOS Device Info'),
//         ),
//         body: Column(
//           children: [
//             Text(''),
//             ElevatedButton(
//                 onPressed: () {
//                   if (Platform.isIOS) {
//                     print('This is IOS.');
//                     Get.snackbar('设备为', 'This is IOS.');
//                   } else if (Platform.isAndroid) {
//                     print('This is Android.');
//                     Get.snackbar('设备为', 'This is Android.');
//                   }
//                   ;
//                 },
//                 child: Text('判断是什么平台')),
//             ElevatedButton(
//                 onPressed: () {
//                   print(Platform.version);
//                   Get.snackbar('设备为', Platform.version);
//                 },
//                 child: Text('ss')),
//             ElevatedButton(
//                 onPressed: () {
//                   getDeviceInfo();
//                 },
//                 child: Text('获取设备消息'))
//           ],
//         ),
//       ),
//     );
//   }
// }

// void getDeviceInfo() async {
//   DeviceInfoPlugin deviceInfo = new DeviceInfoPlugin();
//   if (Platform.isAndroid) {
//     AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
//     print(androidInfo.manufacturer); // 产品/硬件的制造商。
//     print(androidInfo.device); //设备名称
//     print(androidInfo.model); //最终产品的最终用户可见名称。
//     print(androidInfo.androidId); // Android硬件设备ID。
//     print(androidInfo.board); //设备基板名称
//     print(androidInfo.bootloader); //获取设备引导程序版本号
//     print(androidInfo.product); //整个产品的名称
//   } else {}
//   // if (Platform.isIOS) {
//   //   IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
//   //   print(iosDeviceInfo.identifierForVendor);
//   // } else if (Platform.isAndroid) {
//   //   AndroidDeviceInfo androidDeviceInfo = await deviceInfo.androidInfo;
//   //   print(androidDeviceInfo.androidId);
//   // }
// }

// void getIndo() async {
//   DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
//   AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;

//   print(androidInfo.manufacturer); // 产品/硬件的制造商。
//   // print(androidInfo.device); //设备名称
//   // print(androidInfo.model); //最终产品的最终用户可见名称。
//   // print(androidInfo.androidId);// Android硬件设备ID。
//   // print(androidInfo.board);//设备基板名称
//   // print(androidInfo.bootloader); //获取设备引导程序版本号
//   // print(androidInfo.product); //整个产品的名称
// }
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'dart:async';

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:device_info/device_info.dart';

class GetDeviceInfo extends StatefulWidget {
  @override
  _GetDeviceInfoState createState() => _GetDeviceInfoState();
}

class _GetDeviceInfoState extends State<GetDeviceInfo> {
  static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
  Map<String, dynamic> _deviceData = <String, dynamic>{};

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    Map<String, dynamic> deviceData = <String, dynamic>{};

    try {
      if (Platform.isAndroid) {
        deviceData = _readAndroidBuildData(await deviceInfoPlugin.androidInfo);
      } else if (Platform.isIOS) {
        deviceData = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo);
      }
    } on PlatformException {
      deviceData = <String, dynamic>{
        'Error:': 'Failed to get platform version.'
      };
    }

    if (!mounted) return;

    setState(() {
      _deviceData = deviceData;
    });
  }

  Map<String, dynamic> _readAndroidBuildData(AndroidDeviceInfo build) {
    return <String, dynamic>{
      'version.securityPatch': build.version.securityPatch,
      'version.sdkInt': build.version.sdkInt,
      'version.release': build.version.release,
      'version.previewSdkInt': build.version.previewSdkInt,
      'version.incremental': build.version.incremental,
      'version.codename': build.version.codename,
      'version.baseOS': build.version.baseOS,
      'board设备基板名称': build.board,
      'bootloader获取设备引导程序版本号': build.bootloader,
      'brand': build.brand,
      'device设备名称': build.device,
      'display': build.display,
      'fingerprint': build.fingerprint,
      'hardware': build.hardware,
      'host': build.host,
      'id': build.id,
      'manufacturer产品/硬件的制造商': build.manufacturer,
      'model//最终产品的最终用户可见名称': build.model,
      'product//整个产品的名称：产品名称': build.product,
      'supported32BitAbis': build.supported32BitAbis,
      'supported64BitAbis': build.supported64BitAbis,
      'supportedAbis': build.supportedAbis,
      'tags': build.tags,
      'type': build.type,
      'isPhysicalDevice': build.isPhysicalDevice,
      'androidIdAndroid硬件设备ID。': build.androidId,
      'systemFeatures': build.systemFeatures,
    };
  }

  Map<String, dynamic> _readIosDeviceInfo(IosDeviceInfo data) {
    return <String, dynamic>{
      'name': data.name,
      'systemName': data.systemName,
      'systemVersion': data.systemVersion,
      'model': data.model,
      'localizedModel': data.localizedModel,
      'identifierForVendor': data.identifierForVendor,
      'isPhysicalDevice': data.isPhysicalDevice,
      'utsname.sysname:': data.utsname.sysname,
      'utsname.nodename:': data.utsname.nodename,
      'utsname.release:': data.utsname.release,
      'utsname.version:': data.utsname.version,
      'utsname.machine:': data.utsname.machine,
    };
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text(
              Platform.isAndroid ? 'Android Device Info' : 'iOS Device Info'),
        ),
        body: ListView(
          children: _deviceData.keys.map((String property) {
            return Row(
              children: <Widget>[
                Container(
                  padding: const EdgeInsets.all(10.0),
                  child: Text(
                    property,
                    style: const TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
                Expanded(
                    child: Container(
                  padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
                  child: Text(
                    '${_deviceData[property]}',
                    maxLines: 10,
                    overflow: TextOverflow.ellipsis,
                  ),
                )),
              ],
            );
          }).toList(),
        ),
      ),
    );
  }
}
